<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找回密码 - 校园生活助手系统</title>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- 引入自定义CSS -->
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
        
        :root {
            --primary-color: #165DFF;
            --secondary-color: #0A2463;
            --accent-color: #3E92CC;
            --text-color: #333;
            --text-light: #666;
            --bg-color: #F8F9FA;
            --card-bg: #fff;
            --border-radius: 12px;
            --box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Poppins', sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.6;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow-x: hidden;
        }
        
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, rgba(22, 93, 255, 0.05), rgba(62, 146, 204, 0.05));
            z-index: -1;
        }
        
        .forgot-container {
            display: flex;
            width: 900px;
            max-width: 90%;
            background-color: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            overflow: hidden;
            animation: slideIn 0.5s ease-out;
        }
        
        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .forgot-banner {
            flex: 1;
            background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
            color: white;
            padding: 40px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }
        
        .forgot-banner::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255, 255, 255, 0.1), transparent 70%);
            transform: rotate(45deg);
        }
        
        .forgot-banner h2 {
            font-size: 2.5rem;
            font-weight: 700;
            margin-bottom: 1rem;
            position: relative;
            z-index: 1;
        }
        
        .forgot-banner p {
            font-size: 1.1rem;
            opacity: 0.9;
            margin-bottom: 2rem;
            position: relative;
            z-index: 1;
        }
        
        .security-features {
            position: relative;
            z-index: 1;
        }
        
        .security-item {
            display: flex;
            align-items: flex-start;
            margin-bottom: 1.2rem;
        }
        
        .security-item i {
            font-size: 1.2rem;
            margin-right: 1rem;
            margin-top: 0.2rem;
            color: rgba(255, 255, 255, 0.9);
        }
        
        .security-item span {
            opacity: 0.9;
        }
        
        .forgot-form-section {
            flex: 1;
            padding: 40px;
            display: flex;
            flex-direction: column;
        }
        
        .form-header {
            text-align: center;
            margin-bottom: 2.5rem;
        }
        
        .logo {
            display: inline-block;
            margin-bottom: 1.5rem;
        }
        
        .logo i {
            font-size: 3.5rem;
            color: var(--primary-color);
        }
        
        .form-header h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--secondary-color);
            margin-bottom: 0.5rem;
        }
        
        .form-header p {
            color: var(--text-light);
            font-size: 0.95rem;
        }
        
        .form-group {
            margin-bottom: 1.5rem;
            position: relative;
        }
        
        .form-label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
            color: var(--text-color);
            font-size: 0.95rem;
        }
        
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #E5E7EB;
            border-radius: 8px;
            font-size: 1rem;
            transition: var(--transition);
            background-color: #fff;
        }
        
        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
        }
        
        .form-control::placeholder {
            color: #A0AEC0;
        }
        
        .input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #A0AEC0;
            font-size: 1rem;
            z-index: 1;
        }
        
        .input-with-icon .form-control {
            padding-left: 45px;
        }
        
        .verification-code {
            display: flex;
            gap: 10px;
            align-items: flex-end;
        }
        
        .verification-code .form-group {
            flex: 1;
            margin-bottom: 0;
        }
        
        .btn-send-code {
            padding: 12px 20px;
            background-color: var(--accent-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            white-space: nowrap;
        }
        
        .btn-send-code:hover:not(:disabled) {
            background-color: var(--primary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(62, 146, 204, 0.3);
        }
        
        .btn-send-code:disabled {
            background-color: #A0AEC0;
            cursor: not-allowed;
        }
        
        .btn-send-code:disabled span {
            animation: pulse 1.5s infinite;
        }
        
        @keyframes pulse {
            0% { opacity: 1; }
            50% { opacity: 0.6; }
            100% { opacity: 1; }
        }
        
        .btn-reset {
            width: 100%;
            padding: 12px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            margin-bottom: 1.5rem;
            position: relative;
            overflow: hidden;
        }
        
        .btn-reset:hover {
            background-color: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.3);
        }
        
        .btn-reset:active {
            transform: translateY(0);
        }
        
        .btn-reset::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 300px;
            height: 300px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            transform: translate(-50%, -50%) scale(0);
            transition: transform 0.5s ease;
        }
        
        .btn-reset:hover::before {
            transform: translate(-50%, -50%) scale(1);
        }
        
        .back-to-login {
            text-align: center;
            font-size: 0.9rem;
            color: var(--text-light);
        }
        
        .back-to-login a {
            color: var(--primary-color);
            font-weight: 500;
            text-decoration: none;
            transition: var(--transition);
        }
        
        .back-to-login a:hover {
            text-decoration: underline;
            color: var(--secondary-color);
        }
        
        .error-message {
            background-color: #FEE2E2;
            color: #B91C1C;
            padding: 12px 15px;
            border-radius: 8px;
            margin-bottom: 1.5rem;
            display: flex;
            align-items: center;
            font-size: 0.9rem;
            opacity: 0;
            transform: translateY(-10px);
            transition: opacity 0.3s ease, transform 0.3s ease;
        }
        
        .error-message.show {
            opacity: 1;
            transform: translateY(0);
        }
        
        .error-message i {
            margin-right: 10px;
            font-size: 1.1rem;
        }
        
        .success-message {
            background-color: #D1FAE5;
            color: #065F46;
            padding: 12px 15px;
            border-radius: 8px;
            margin-bottom: 1.5rem;
            display: flex;
            align-items: center;
            font-size: 0.9rem;
            opacity: 0;
            transform: translateY(-10px);
            transition: opacity 0.3s ease, transform 0.3s ease;
        }
        
        .success-message.show {
            opacity: 1;
            transform: translateY(0);
        }
        
        .success-message i {
            margin-right: 10px;
            font-size: 1.1rem;
        }
        
        /* 加载动画 */
        .loader {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
            margin-left: 8px;
            vertical-align: middle;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        .btn-reset.loading .btn-text {
            visibility: hidden;
        }
        
        .btn-reset.loading .loader {
            display: inline-block;
        }
        
        /* 步骤指示器 */
        .step-indicator {
            display: flex;
            justify-content: space-between;
            margin-bottom: 2rem;
            position: relative;
        }
        
        .step-indicator::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 2px;
            background-color: #E5E7EB;
            z-index: 0;
            transform: translateY(-50%);
        }
        
        .step-progress {
            position: absolute;
            top: 50%;
            left: 0;
            height: 2px;
            background-color: var(--primary-color);
            z-index: 1;
            transform: translateY(-50%);
            transition: width 0.3s ease;
            width: 0%; /* 默认第一步骤 */
        }
        
        .step {
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
            z-index: 2;
        }
        
        .step-number {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: #E5E7EB;
            color: var(--text-light);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            margin-bottom: 0.5rem;
            transition: var(--transition);
        }
        
        .step.active .step-number {
            background-color: var(--primary-color);
            color: white;
        }
        
        .step.completed .step-number {
            background-color: var(--primary-color);
            color: white;
        }
        
        .step.completed .step-number i {
            display: block;
        }
        
        .step.completed .step-number span {
            display: none;
        }
        
        .step-label {
            font-size: 0.8rem;
            color: var(--text-light);
            text-align: center;
            max-width: 80px;
        }
        
        .step.active .step-label {
            color: var(--primary-color);
            font-weight: 500;
        }
        
        /* 表单步骤 */
        .form-step {
            display: none;
        }
        
        .form-step.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }
        
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .forgot-container {
                flex-direction: column;
                max-width: 100%;
                margin: 20px;
            }
            
            .forgot-banner {
                padding: 30px 20px;
                text-align: center;
            }
            
            .forgot-banner h2 {
                font-size: 2rem;
            }
            
            .security-item {
                justify-content: center;
            }
            
            .forgot-form-section {
                padding: 30px 20px;
            }
        }
        
        @media (max-width: 480px) {
            body {
                align-items: flex-start;
                padding-top: 20px;
                height: auto;
                min-height: 100vh;
            }
            
            .forgot-banner h2 {
                font-size: 1.8rem;
            }
            
            .forgot-banner p {
                font-size: 1rem;
            }
            
            .form-header h1 {
                font-size: 1.6rem;
            }
            
            .verification-code {
                flex-direction: column;
                gap: 15px;
            }
            
            .btn-send-code {
                width: 100%;
            }
            
            .step-label {
                font-size: 0.7rem;
                max-width: 60px;
            }
        }
    </style>
</head>
<body>
    <div class="forgot-container">
        <!-- 左侧横幅 -->
        <div class="forgot-banner">
            <h2>密码找回</h2>
            <p>安全快捷地重置您的密码，重新获取您的账号访问权限</p>
            <div class="security-features">
                <div class="security-item">
                    <i class="fa fa-shield"></i>
                    <span>多重身份验证，保障账号安全</span>
                </div>
                <div class="security-item">
                    <i class="fa fa-clock-o"></i>
                    <span>快速响应，即时重置</span>
                </div>
                <div class="security-item">
                    <i class="fa fa-lock"></i>
                    <span>全程加密，保护您的隐私</span>
                </div>
                <div class="security-item">
                    <i class="fa fa-question-circle"></i>
                    <span>如有疑问，请联系技术支持</span>
                </div>
            </div>
        </div>
        
        <!-- 右侧表单 -->
        <div class="forgot-form-section">
            <div class="form-header">
                <div class="logo">
                    <i class="fa fa-key"></i>
                </div>
                <h1>找回您的密码</h1>
                <p>按照步骤操作，安全重置您的账号密码</p>
            </div>
            
            <!-- 消息提示区域 -->
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <div class="alert alert-{{ category }} fade-in mb-4" role="alert">
                            <button type="button" class="close" data-bs-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            {{ message }}
                        </div>
                    {% endfor %}
                {% endif %}
            {% endwith %}
            
            <!-- 错误消息区域 -->
            <div class="error-message" id="error-message" style="display: none;">
                <i class="fa fa-exclamation-circle"></i>
                <span id="error-text">发生错误，请重试</span>
            </div>
            
            <!-- 成功消息区域 -->
            <div class="success-message" id="success-message" style="display: none;">
                <i class="fa fa-check-circle"></i>
                <span id="success-text">验证码已发送，请查收</span>
            </div>
            
            <!-- 步骤指示器 -->
            <div class="step-indicator">
                <div class="step-progress" id="step-progress"></div>
                <div class="step active" id="step-1">
                    <div class="step-number">
                        <span>1</span>
                        <i class="fa fa-check"></i>
                    </div>
                    <div class="step-label">验证身份</div>
                </div>
                <div class="step" id="step-2">
                    <div class="step-number">
                        <span>2</span>
                        <i class="fa fa-check"></i>
                    </div>
                    <div class="step-label">验证码验证</div>
                </div>
                <div class="step" id="step-3">
                    <div class="step-number">
                        <span>3</span>
                        <i class="fa fa-check"></i>
                    </div>
                    <div class="step-label">重置密码</div>
                </div>
                <div class="step" id="step-4">
                    <div class="step-number">
                        <span>4</span>
                        <i class="fa fa-check"></i>
                    </div>
                    <div class="step-label">完成</div>
                </div>
            </div>
            
            <!-- 表单步骤1：验证身份 -->
            <div class="form-step active" id="form-step-1">
                <form method="POST" action="{{ url_for('forgot_password') }}" id="forgot-form-step-1">
                    {{ form.hidden_tag() }}
                    
                    <div class="form-group input-with-icon">
                        <label for="username" class="form-label">用户名/学号/工号</label>
                        <i class="fa fa-user input-icon"></i>
                        <input type="text" class="form-control" id="username" name="username" placeholder="请输入您的用户名" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">验证方式</label>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="verify_method" id="verify_email" value="email" checked>
                            <label class="form-check-label" for="verify_email">邮箱验证</label>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="verify_method" id="verify_phone" value="phone">
                            <label class="form-check-label" for="verify_phone">手机验证</label>
                        </div>
                    </div>
                    
                    <div id="email-container" class="form-group input-with-icon">
                        <label for="email" class="form-label">注册邮箱</label>
                        <i class="fa fa-envelope input-icon"></i>
                        <input type="email" class="form-control" id="email" name="email" placeholder="请输入您的注册邮箱" required>
                    </div>
                    
                    <div id="phone-container" class="form-group input-with-icon" style="display: none;">
                        <label for="phone" class="form-label">注册手机号</label>
                        <i class="fa fa-mobile input-icon"></i>
                        <input type="tel" class="form-control" id="phone" name="phone" placeholder="请输入您的注册手机号">
                    </div>
                    
                    <button type="button" class="btn-reset" id="next-step-1">
                        <span class="btn-text">下一步</span>
                        <div class="loader" style="display: none;"></div>
                    </button>
                </form>
            </div>
            
            <!-- 表单步骤2：验证码验证 -->
            <div class="form-step" id="form-step-2">
                <div class="form-group">
                    <p class="text-muted" id="verification-message">验证码已发送至您的邮箱，请查收。</p>
                </div>
                
                <div class="verification-code">
                    <div class="form-group input-with-icon">
                        <label for="verification_code" class="form-label">验证码</label>
                        <i class="fa fa-shield input-icon"></i>
                        <input type="text" class="form-control" id="verification_code" placeholder="请输入验证码" maxlength="6" required>
                    </div>
                    <button type="button" class="btn-send-code" id="resend-code">
                        <span>重新发送 (60s)</span>
                    </button>
                </div>
                
                <div class="d-grid gap-2" style="margin-top: 1.5rem;">
                    <button type="button" class="btn-reset" id="next-step-2">
                        <span class="btn-text">验证</span>
                        <div class="loader" style="display: none;"></div>
                    </button>
                    <button type="button" class="btn btn-outline-secondary" id="back-to-step-1">
                        返回上一步
                    </button>
                </div>
            </div>
            
            <!-- 表单步骤3：重置密码 -->
            <div class="form-step" id="form-step-3">
                <div class="form-group input-with-icon">
                    <label for="new_password" class="form-label">新密码</label>
                    <i class="fa fa-lock input-icon"></i>
                    <input type="password" class="form-control" id="new_password" placeholder="请输入新密码" required>
                    <i class="fa fa-eye-slash password-toggle" id="toggle-new-password" style="position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #A0AEC0; font-size: 1.1rem;"></i>
                </div>
                
                <div class="form-group input-with-icon">
                    <label for="confirm_password" class="form-label">确认新密码</label>
                    <i class="fa fa-lock input-icon"></i>
                    <input type="password" class="form-control" id="confirm_password" placeholder="请再次输入新密码" required>
                    <i class="fa fa-eye-slash password-toggle" id="toggle-confirm-password" style="position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #A0AEC0; font-size: 1.1rem;"></i>
                </div>
                
                <div class="form-group">
                    <div class="password-strength" id="password-strength">
                        <div class="strength-indicator">
                            <div class="strength-bar" id="strength-bar-1"></div>
                            <div class="strength-bar" id="strength-bar-2"></div>
                            <div class="strength-bar" id="strength-bar-3"></div>
                        </div>
                        <div class="strength-text" id="strength-text">密码强度：未设置</div>
                    </div>
                </div>
                
                <div class="d-grid gap-2" style="margin-top: 1.5rem;">
                    <button type="button" class="btn-reset" id="next-step-3">
                        <span class="btn-text">重置密码</span>
                        <div class="loader" style="display: none;"></div>
                    </button>
                    <button type="button" class="btn btn-outline-secondary" id="back-to-step-2">
                        返回上一步
                    </button>
                </div>
            </div>
            
            <!-- 表单步骤4：完成 -->
            <div class="form-step" id="form-step-4">
                <div class="text-center" style="padding: 30px 0;">
                    <div style="width: 100px; height: 100px; background-color: #D1FAE5; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px;">
                        <i class="fa fa-check" style="font-size: 3rem; color: #065F46;"></i>
                    </div>
                    <h2 style="margin-bottom: 15px; color: var(--secondary-color);">密码重置成功！</h2>
                    <p style="margin-bottom: 30px; color: var(--text-light);">您的密码已成功重置，请使用新密码登录系统。</p>
                    <a href="{{ url_for('login') }}" class="btn btn-primary" style="padding: 12px 40px; font-weight: 600;">
                        立即登录
                    </a>
                </div>
            </div>
            
            <div class="back-to-login">
                <a href="{{ url_for('login') }}">返回登录页面</a>
            </div>
        </div>
    </div>

    <!-- 引入Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 当前步骤
            let currentStep = 1;
            const totalSteps = 4;
            
            // 表单元素
            const stepProgress = document.getElementById('step-progress');
            const verificationMethod = document.getElementsByName('verify_method');
            const emailContainer = document.getElementById('email-container');
            const phoneContainer = document.getElementById('phone-container');
            const verificationMessage = document.getElementById('verification-message');
            const newPasswordInput = document.getElementById('new_password');
            const confirmPasswordInput = document.getElementById('confirm_password');
            
            // 按钮
            const nextStep1Btn = document.getElementById('next-step-1');
            const nextStep2Btn = document.getElementById('next-step-2');
            const nextStep3Btn = document.getElementById('next-step-3');
            const backToStep1Btn = document.getElementById('back-to-step-1');
            const backToStep2Btn = document.getElementById('back-to-step-2');
            const resendCodeBtn = document.getElementById('resend-code');
            const toggleNewPasswordBtn = document.getElementById('toggle-new-password');
            const toggleConfirmPasswordBtn = document.getElementById('toggle-confirm-password');
            
            // 消息元素
            const errorMessage = document.getElementById('error-message');
            const successMessage = document.getElementById('success-message');
            const errorText = document.getElementById('error-text');
            const successText = document.getElementById('success-text');
            
            // 密码强度元素
            const strengthBars = [
                document.getElementById('strength-bar-1'),
                document.getElementById('strength-bar-2'),
                document.getElementById('strength-bar-3')
            ];
            const strengthText = document.getElementById('strength-text');
            
            // 设置密码强度样式
            const strengthStyles = {
                weak: {
                    bars: ['#EF4444', '#E5E7EB', '#E5E7EB'],
                    text: '密码强度：弱',
                    textColor: '#EF4444'
                },
                medium: {
                    bars: ['#F59E0B', '#F59E0B', '#E5E7EB'],
                    text: '密码强度：中',
                    textColor: '#F59E0B'
                },
                strong: {
                    bars: ['#10B981', '#10B981', '#10B981'],
                    text: '密码强度：强',
                    textColor: '#10B981'
                }
            };
            
            // 切换验证方式
            verificationMethod.forEach(radio => {
                radio.addEventListener('change', function() {
                    if (this.value === 'email') {
                        emailContainer.style.display = 'block';
                        phoneContainer.style.display = 'none';
                        document.getElementById('email').setAttribute('required', 'required');
                        document.getElementById('phone').removeAttribute('required');
                    } else {
                        emailContainer.style.display = 'none';
                        phoneContainer.style.display = 'block';
                        document.getElementById('phone').setAttribute('required', 'required');
                        document.getElementById('email').removeAttribute('required');
                    }
                });
            });
            
            // 密码显示/隐藏切换
            toggleNewPasswordBtn.addEventListener('click', function() {
                togglePasswordVisibility(newPasswordInput, this);
            });
            
            toggleConfirmPasswordBtn.addEventListener('click', function() {
                togglePasswordVisibility(confirmPasswordInput, this);
            });
            
            function togglePasswordVisibility(input, button) {
                const type = input.getAttribute('type') === 'password' ? 'text' : 'password';
                input.setAttribute('type', type);
                
                // 切换图标
                button.classList.toggle('fa-eye');
                button.classList.toggle('fa-eye-slash');
            }
            
            // 密码强度检测
            newPasswordInput.addEventListener('input', function() {
                const password = this.value;
                let strength = 'weak';
                
                // 简单的密码强度检测逻辑
                if (password.length >= 8) {
                    // 包含字母和数字
                    if (/[a-zA-Z]/.test(password) && /[0-9]/.test(password)) {
                        // 包含特殊字符
                        if (/[^a-zA-Z0-9]/.test(password)) {
                            strength = 'strong';
                        } else {
                            strength = 'medium';
                        }
                    }
                }
                
                // 更新密码强度指示器
                updatePasswordStrength(strength);
            });
            
            function updatePasswordStrength(strength) {
                const style = strengthStyles[strength];
                
                for (let i = 0; i < strengthBars.length; i++) {
                    strengthBars[i].style.height = '4px';
                    strengthBars[i].style.width = '100%';
                    strengthBars[i].style.backgroundColor = style.bars[i];
                    strengthBars[i].style.borderRadius = '2px';
                    strengthBars[i].style.marginRight = i < strengthBars.length - 1 ? '5px' : '0';
                    strengthBars[i].style.transition = 'all 0.3s ease';
                }
                
                strengthText.textContent = style.text;
                strengthText.style.color = style.textColor;
            }
            
            // 步骤导航
            nextStep1Btn.addEventListener('click', function() {
                const username = document.getElementById('username').value.trim();
                const isEmail = document.getElementById('verify_email').checked;
                const contact = isEmail ? document.getElementById('email').value.trim() : document.getElementById('phone').value.trim();
                
                // 简单的表单验证
                if (!username) {
                    showError('请输入用户名');
                    return;
                }
                
                if (!contact) {
                    showError(isEmail ? '请输入邮箱' : '请输入手机号');
                    return;
                }
                
                if (isEmail && !validateEmail(contact)) {
                    showError('请输入有效的邮箱地址');
                    return;
                }
                
                if (!isEmail && !validatePhone(contact)) {
                    showError('请输入有效的手机号码');
                    return;
                }
                
                // 显示加载状态
                this.classList.add('loading');
                
                // 模拟验证请求
                setTimeout(() => {
                    // 隐藏加载状态
                    this.classList.remove('loading');
                    
                    // 更新验证消息
                    verificationMessage.textContent = isEmail 
                        ? `验证码已发送至邮箱 ${contact}，请查收。` 
                        : `验证码已发送至手机 ${contact.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}，请查收。`;
                    
                    // 进入下一步
                    goToStep(2);
                    
                    // 开始倒计时
                    startResendCountdown();
                    
                    // 显示成功消息
                    showSuccess(isEmail ? '验证码已发送至您的邮箱，请查收' : '验证码已发送至您的手机，请查收');
                }, 1500);
            });
            
            nextStep2Btn.addEventListener('click', function() {
                const verificationCode = document.getElementById('verification_code').value.trim();
                
                // 简单的验证码验证
                if (!verificationCode || verificationCode.length !== 6 || !/^\d+$/.test(verificationCode)) {
                    showError('请输入6位数字验证码');
                    return;
                }
                
                // 显示加载状态
                this.classList.add('loading');
                
                // 模拟验证请求
                setTimeout(() => {
                    // 隐藏加载状态
                    this.classList.remove('loading');
                    
                    // 进入下一步
                    goToStep(3);
                }, 1500);
            });
            
            nextStep3Btn.addEventListener('click', function() {
                const newPassword = newPasswordInput.value;
                const confirmPassword = confirmPasswordInput.value;
                
                // 简单的密码验证
                if (!newPassword || newPassword.length < 8) {
                    showError('新密码长度至少为8位');
                    return;
                }
                
                if (newPassword !== confirmPassword) {
                    showError('两次输入的密码不一致');
                    return;
                }
                
                // 显示加载状态
                this.classList.add('loading');
                
                // 模拟重置请求
                setTimeout(() => {
                    // 隐藏加载状态
                    this.classList.remove('loading');
                    
                    // 进入下一步
                    goToStep(4);
                }, 1500);
            });
            
            backToStep1Btn.addEventListener('click', function() {
                goToStep(1);
            });
            
            backToStep2Btn.addEventListener('click', function() {
                goToStep(2);
            });
            
            resendCodeBtn.addEventListener('click', function() {
                // 开始倒计时
                startResendCountdown();
                
                // 显示成功消息
                const isEmail = document.getElementById('verify_email').checked;
                showSuccess(isEmail ? '验证码已重新发送至您的邮箱' : '验证码已重新发送至您的手机');
            });
            
            function goToStep(step) {
                // 隐藏所有步骤
                document.querySelectorAll('.form-step').forEach(formStep => {
                    formStep.classList.remove('active');
                });
                
                // 更新步骤指示器
                document.querySelectorAll('.step').forEach((stepEl, index) => {
                    const stepNum = index + 1;
                    
                    if (stepNum < step) {
                        // 已完成的步骤
                        stepEl.classList.remove('active');
                        stepEl.classList.add('completed');
                    } else if (stepNum === step) {
                        // 当前步骤
                        stepEl.classList.add('active');
                        stepEl.classList.remove('completed');
                    } else {
                        // 未完成的步骤
                        stepEl.classList.remove('active', 'completed');
                    }
                });
                
                // 更新进度条
                stepProgress.style.width = ((step - 1) / (totalSteps - 1)) * 100 + '%';
                
                // 显示当前步骤
                document.getElementById(`form-step-${step}`).classList.add('active');
                
                // 更新当前步骤
                currentStep = step;
            }
            
            function startResendCountdown() {
                let countdown = 60;
                resendCodeBtn.disabled = true;
                resendCodeBtn.innerHTML = `<span>重新发送 (${countdown}s)</span>`;
                
                const timer = setInterval(() => {
                    countdown--;
                    resendCodeBtn.innerHTML = `<span>重新发送 (${countdown}s)</span>`;
                    
                    if (countdown <= 0) {
                        clearInterval(timer);
                        resendCodeBtn.disabled = false;
                        resendCodeBtn.innerHTML = '<span>重新发送</span>';
                    }
                }, 1000);
            }
            
            function showError(message) {
                errorText.textContent = message;
                errorMessage.style.display = 'flex';
                
                // 触发重排以应用动画
                errorMessage.offsetHeight;
                
                errorMessage.style.opacity = '1';
                errorMessage.style.transform = 'translateY(0)';
                
                // 添加抖动动画
                errorMessage.style.animation = 'none';
                errorMessage.offsetHeight;
                errorMessage.style.animation = 'shake 0.5s ease-in-out';
                
                // 5秒后自动隐藏错误消息
                setTimeout(function() {
                    errorMessage.style.opacity = '0';
                    errorMessage.style.transform = 'translateY(-10px)';
                    setTimeout(() => {
                        errorMessage.style.display = 'none';
                    }, 300);
                }, 5000);
            }
            
            function showSuccess(message) {
                successText.textContent = message;
                successMessage.style.display = 'flex';
                
                // 触发重排以应用动画
                successMessage.offsetHeight;
                
                successMessage.style.opacity = '1';
                successMessage.style.transform = 'translateY(0)';
                
                // 5秒后自动隐藏成功消息
                setTimeout(function() {
                    successMessage.style.opacity = '0';
                    successMessage.style.transform = 'translateY(-10px)';
                    setTimeout(() => {
                        successMessage.style.display = 'none';
                    }, 300);
                }, 5000);
            }
            
            function validateEmail(email) {
                const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                return re.test(email);
            }
            
            function validatePhone(phone) {
                const re = /^1[3-9]\d{9}$/;
                return re.test(phone);
            }
            
            // 添加自定义抖动动画
            const style = document.createElement('style');
            style.textContent = `
                @keyframes shake {
                    0%, 100% { transform: translateX(0); }
                    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
                    20%, 40%, 60%, 80% { transform: translateX(5px); }
                }
                
                .strength-indicator {
                    display: flex;
                    margin-bottom: 5px;
                }
            `;
            document.head.appendChild(style);
            
            // 添加页面载入动画效果
            document.body.style.opacity = '0';
            setTimeout(function() {
                document.body.style.transition = 'opacity 0.5s ease';
                document.body.style.opacity = '1';
            }, 100);
        });
    </script>
</body>
</html>